<?php

if (in_array($_SERVER['HTTP_HOST'], array("127.0.0.1", "localhost"))) {
    /////////////////////////////////////////////////////////////////////
    // SITE EN DEVELOPPEMENT
    /////////////////////////////////////////////////////////////////////
    $hote = "localhost";
    $user = "root";
    $pass = "";
    $db = "aquarium";
} else {
    /////////////////////////////////////////////////////////////////////
    // SITE EN INTEGRATION/PRODUCTION
    /////////////////////////////////////////////////////////////////////
    $hote = "mysql51-75.perso";
    $user = "aquariumf";
    $pass = "qCO47lh6";
    $db = "aquariumf";
}



$conn = @mysql_connect($hote, $user, $pass);
@mysql_select_db($db);
@mysql_set_charset('utf8');

function tronque($chaine, $longueur = 120) {
    if (empty($chaine)) {
        return "";
    } elseif (strlen($chaine) < $longueur) {
        return $chaine;
    } elseif (preg_match("/(.{1,$longueur})\s./ms", $chaine, $match)) {
        return $match [1] . "...";
    } else {
        return substr($chaine, 0, $longueur) . "...";
    }
}

function caractereValideUrl($chaine) {
    $chaine = strtolower($chaine);
    // supprime les caracteres speciaux
    $accents = Array("/È/", "/É/", "/Ê/", "/Ë/", "/é/", "/è/", "/ê/", "/ë/", "/ç/", "/À/", "/Á/", "/Â/", "/Ã/", "/Ä/", "/Å/", "/à/", "/â/", "/á/", "/ä/", "/ã/", "/å/", "/î/", "/ï/", "/í/", "/ì/", "/ù/", "/ô/", "/ò/", "/ó/", "/ö/");
    $sans = Array("e", "e", "e", "e", "e", "e", "e", "e", "c", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "i", "i", "i", "i", "u", "o", "o", "o", "o");
    $chaine = preg_replace($accents, $sans, $chaine);
    $chaine = preg_replace('#[^A-Za-z0-9]#', '-', $chaine);

    //supprime les double tiret
    while (strpos($chaine, '--') !== false)
        $chaine = str_replace('--', '-', $chaine);

    // Supprime le dernier caractère si c'est un tiret
    $chaine = rtrim($chaine, '-');
    return $chaine;
}

function check($val, $test, $type) {
    if ($val == $test) {
        if ($type == 'select')
            return 'selected';
        else
            return 'checked';
    }
}

function filtre($mot) {
    //retourne si le mot est plus grand que 2 lettres
    if ((strlen($mot)) > 2)
        return($mot);
}

function get_ip() {
	// IP si internet partagé
	if (isset($_SERVER['HTTP_CLIENT_IP'])) {
		return $_SERVER['HTTP_CLIENT_IP'];
	}
	// IP derrière un proxy
	elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		return $_SERVER['HTTP_X_FORWARDED_FOR'];
	}
	// Sinon : IP normale
	else {
		return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
	}
}

function floatPoint($nbr){
    return str_replace(',', '.', $nbr);
}
?>
